package io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class IOTest4 {
	
	public static void main(String[] args) throws Exception 
	{
		List<String> banwords = new ArrayList<String>();
		List<String> antiwords = new ArrayList<String>();
		List<String> replacewords = new ArrayList<String>();
		File f = new File("H:/黑马JavaWeb30天课程/源代码/day19_word/WebRoot/WEB-INF/classes");
		File [] f1 = f.listFiles();
        System.out.println(Thread.currentThread().getContextClassLoader().getResource("").getPath());
		BufferedReader br = null;
		for(File f2 :f1){
			if(f2.isFile()){
			try {
				br = new BufferedReader(new InputStreamReader(new FileInputStream(f2), "gb2312"));
				String line ;
				try {
					while((line=br.readLine())!=null){
						String [] s = line.split("\\|");
						if(s.length!=2)
							continue;
						String word = s[0].trim();
						String level = s[1].trim();
						if("1".equals(level))
							banwords.add(word);
						if("2".equals(level))
							antiwords.add(word);
						if("3".equals(level))
							replacewords.add(word);
						
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			finally{
				if(br!=null){
					try {
						br.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			}
			
			
		}
		System.out.println(banwords.size());
		System.out.println(banwords.toString());
		System.out.println(antiwords.size());
		System.out.println(replacewords.size());
		
		
	}

}
